package web.tag;
import domain.Activity;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.text.SimpleDateFormat;

/**
 * activity详细信息展示标签
 * 结合modal实现activity的详细信息的展示
 *
 * @author shicm
 */
public class ShowActivityInfoTag extends SimpleTagSupport {

    /** 要展示的活动 */
    private Activity activity;

    /**
     * 设置要展示的活动
     *
     * @param activity 活动
     */
    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    /**
     * 展示活动详细信息
     *
     * @throws JspException JSP异常
     * @throws IOException IO异常
     */
    @Override
    public void doTag() throws JspException, IOException {
            JspWriter out = getJspContext().getOut();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String outPrint = "";
            outPrint += "<p><span class=\"fw-semibold\">活动ID: &nbsp;&nbsp;</span>"+activity.getActivityID()+"</p>";
            outPrint += "<p><span class=\"fw-semibold\">活动名称: &nbsp;&nbsp;</span>"+activity.getActivityName()+"</p>";
            outPrint += "<p><span class=\"fw-semibold\">开始时间: &nbsp;&nbsp;</span>"+sdf.format(activity.getStartTime())+"</p>";
            outPrint += "<p><span class=\"fw-semibold\">结束时间: &nbsp;&nbsp;</span>"+sdf.format(activity.getEndTime())+"</p>";
            outPrint += "<p><span class=\"fw-semibold\">活动地点: &nbsp;&nbsp;</span>"+activity.getPlace()+"</p>";
            outPrint += "<p><span class=\"fw-semibold\">活动描述: &nbsp;&nbsp;</span>"+activity.getDescription()+"</p>";
            out.write(outPrint);
        }
    }